#!/bin/bash
#
# chkconfig: 2345 96 04
# description: PSPacer control daemon
# processname: pspd

PSPD=/usr/sbin/pspd

. /etc/rc.d/init.d/functions

[ -x $PSPD ] || exit 0

RETVAL=0

start () {
	echo -n "Starting pspd: "
	if [ -f /var/lock/subsys/pspd ]; then
		echo "pspd is already running"
		failure
	else
		/etc/sysconfig/pspd/add
		daemon $PSPD -d
		RETVAL=$?
	fi
	echo
	[ $RETVAL = 0 ] && touch /var/lock/subsys/pspd
	return $RETVAL
}

stop () {
	echo -n "Stopping pspd: "
	killproc $PSPD
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f /var/lock/subsys/pspd
	[ $RETVAL = 0 ] && /etc/sysconfig/pspd/del
	return $RETVAL
}

restart () {
	stop
	start
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart)
	restart
	;;
    status)
	status $PSPD
	RETVAL=$?
	;;
    *)
        echo "Usage: pspd {start|stop|restart|status}"
        RETVAL=1
esac

exit $RETVAL
